package com.sugar.psych.assessment.module.business.dal.mysql.psychquestion;


import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.mybatis.core.mapper.BaseMapperX;
import com.sugar.psych.assessment.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.sugar.psych.assessment.module.business.dal.dataobject.psychquestion.PsychQuestionDO;
import com.sugar.psych.assessment.module.business.dal.dataobject.psychquestionbank.PsychQuestionBankDO;
import org.apache.ibatis.annotations.Mapper;
import com.sugar.psych.assessment.module.business.controller.admin.psychquestion.vo.*;

/**
 * 心理测评题目 Mapper
 *
 * @author Ysugar
 */
@Mapper
public interface PsychQuestionMapper extends BaseMapperX<PsychQuestionDO> {

    default PageResult<PsychQuestionRespVO> selectPage(PsychQuestionPageReqVO reqVO) {
        return selectJoinPage(reqVO, PsychQuestionRespVO.class, new MPJLambdaWrapperX<PsychQuestionDO>()
                .selectAll(PsychQuestionDO.class)
                .selectAs(PsychQuestionBankDO::getTitle, PsychQuestionRespVO::getBankTitle)
                .leftJoin(PsychQuestionBankDO.class, PsychQuestionBankDO::getId, PsychQuestionDO::getBankId)
                .eqIfPresent(PsychQuestionDO::getBankId, reqVO.getBankId())
                .likeIfPresent(PsychQuestionDO::getTitle, reqVO.getTitle())
                .eqIfPresent(PsychQuestionDO::getQuestionType, reqVO.getQuestionType())
                .betweenIfPresent(PsychQuestionDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PsychQuestionDO::getId));
    }

}